/*
 * TripManager.cpp
 *
 *  Created on: Apr 30, 2010
 *      Author: Sequoyha
 */

#include "TripManager.h"
#include "Menus.h"

//Constructor--------------------------------------------------------
TripManager::TripManager()
{
	WineryList tripList;
	tripList.initializeListFromFile();
	tripList.printList();
	toVisit = tripList.getList();
	allTotal = 0.00;
}
/*********************************************************************
 * goToWinery
 *
 * Sets winery vector iterator to proper for other functions to operate
 *
 * Pre-conditions: nextWinery value must be passed in for looping
 *
 * Post-conditions: tv iterator set to proper position
 *******************************************************************/
void TripManager::goToWinery(int nextWinery)
{
	//set tv to start point of vector
	tv = toVisit.begin();
	//check to make sure input value is within range
	if(nextWinery > Winery::totalWineries)
	{
		//OUTPUT - error output
		cout << "Winery # " << nextWinery << " is an invalid Winery\n";
	}
	else
	{
		//Loop to proper winery
		for(int i = 0; i < nextWinery-1; i++)
		{
			tv++;
		}
	}
}
/*********************************************************************
 * findWineryInfo
 *
 * Gets info from current winery (tv position) and displays info to
 * screen. Allows user to opt to make purchases
 *
 * Pre-conditions: tv must be set to proper winery beforehand
 *
 * Post-conditions: none
 *******************************************************************/
void TripManager::findWineryInfo()
{
	char choice;		//choice to shop or not
	store = *tv;
	//OUTPUT--------------------------------------------------------
	cout << "\nWelcome to " << store.getWineryName() << endl << endl;
	cout << "Our current selection of wines:\n";
	//Print List of wines to screen
	store.PrintWines();
	cout << "Would you like to purchase any wine during your visit?(Y or N) ";
	//INPUT - shop or not?
	choice = MenuInput();
	if(choice == 'Y')
	{
		//Call to shop wines
		shopCurrentWinery();
	}
	//OUTPUT--------------------------------------------------------------
	cout << "\nThank you for visiting " << store.getWineryName() << ".\n";
	cout << "Enjoy the rest of your tour!\n";

}
/*********************************************************************
 * shopCurrentWinery
 *
 * Allows user to shop for wines in the currently selected winery
 *
 * Pre-conditions: store must exist prior to function call
 *
 * Post-conditions: none
 *******************************************************************/
void TripManager::shopCurrentWinery()
{
	int wineSelection, qty;
	char choice;
	Transaction here(store); //New transaction object for current store
	do
	{
		//OUTPUT - print wines and ask for purchase
		store.PrintWines();
		cout << "Which wine would you like to purchase?: ";
		//INPUT - get wine and quantity to purchase
		cin >> wineSelection;
		cout << "How many would you like to purchase?: ";
		cin >> qty;
		//Process sale
		here.addSale(wineSelection, qty);
		//OUTPUT - notify user of current purchase
		here.PrintSales();
		//Query for loop
		cout << "Would you like to make another purchase?: ";
		choice = MenuInput();
	}while(choice == 'Y');
	//Add sales from current winery to all sales for tour
	allSales.push_back(here);
}
/*********************************************************************
 * finishTrip
 *
 * Prints record for all sales made during wine tour
 *
 * Pre-conditions: allSales vector must have information
 *
 * Post-conditions: none
 *******************************************************************/
void TripManager::finishTrip()
{
	system("cls");
	cout << "TRANSACTION RECORD FOR ALL WINERIES VISITED\n\n";
	//Loop to print sales from all wineries
	for(as = allSales.begin(); as < allSales.end(); as++)
	{
		//Call print sales for current winery
		as->PrintSales();
		//Add each grand Total to total sales from all wineries
		allTotal += as->getGrandTotal();
	}
	//OUTPUT total from all wineries
	cout << "Total spent at all wineries: $" << allTotal << endl;
}
